/**
 * 
 */
package com.thinkgsp.sys.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Date;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * 系统期间类，记录每个期间的起始日期与结束日期
 * @author evan
 *
 */
public class SysAccountPeriod extends SysModel implements Serializable {

	private static final long serialVersionUID = 1760260328443782531L;

	private Integer id;
	private Integer fyear;
	private Integer period;
	private Date beginDate;
	private Date endDate;
	private Boolean current;
	
	/**
	 * id
	 * @return
	 */
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * 年份
	 * @return
	 */
	public Integer getFyear() {
		return fyear;
	}

	public void setFyear(Integer fyear) {
		this.fyear = fyear;
	}

	/**
	 * 期间
	 * @return
	 */
	public Integer getPeriod() {
		return period;
	}

	public void setPeriod(Integer period) {
		this.period = period;
	}

	/**
	 * 开始日期
	 * @return
	 */
	public Date getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	/**
	 * 截止日期
	 * @return
	 */
	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	/**
	 * 是否当前期间
	 * @return
	 */
	public Boolean getCurrent() {
		return current;
	}

	public void setCurrent(Boolean current) {
		this.current = current;
	}
	
	public BigDecimal periodNumber() {
		double val = this.fyear + this.period/100.0;
		return new BigDecimal(val).setScale(2, BigDecimal.ROUND_HALF_DOWN);
	}

	/* (non-Javadoc)
	 * @see com.thinkgsp.sys.model.SysModel#toString()
	 */
	@Override
	public String toString() {
		ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE);
		sb.append("id",this.id)
		  .append("fyear",this.fyear)
		  .append("period",this.period)
		  .append("current",this.current);
		
		return sb.toString();
	}

	/* (non-Javadoc)
	 * @see com.thinkgsp.sys.model.SysModel#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object o) {
		if(this == o) {
			return true;
		}
		if(!(o instanceof SysAccountPeriod)) {
			return false;
		}
		final SysAccountPeriod ap = (SysAccountPeriod)o;
		if(id != null) {
			return id.equals(ap.getId());
		} else {
			if(fyear == ap.getFyear() && period == ap.getPeriod()) {
				return true;
			} else {
				return false;
			}
		}
	}

	/* (non-Javadoc)
	 * @see com.thinkgsp.sys.model.SysModel#hashCode()
	 */
	@Override
	public int hashCode() {
		return (this.id != null ? this.id.hashCode() : 0);
	}

}
